package sync

import (
	"promsync/cmd/config"
	sync "promsync/sync/base"
)

type AlertManagerConfigSync struct {
	Config *config.AppConfig
}

func (alert *AlertManagerConfigSync) Sync() {

	go func() {
		event := make(chan string, 2)
		fetcher := &sync.Fetcher{
			Group: alert.Config.AlertManager.Group, DataId: alert.Config.AlertManager.DataId,
		}
		fetcher.Listener(event)

		notify := sync.HttpNotify{
			Url: alert.Config.AlertManager.Url,
		}
		s := &sync.Sink{
			Fetch: fetcher, ConfigFile: alert.Config.AlertManager.ConfigFile,
		}
		for {
			select {
			case data := <-event:
				s.SinkConfig(data)
				notify.Notify()
			}
		}
	}()

}
